package com.kws.merchant.service.impl;


import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.kws.common.core.constant.SecurityConstants;
import com.kws.common.core.domain.R;
import com.kws.common.security.auth.AuthUtil;
import com.kws.merchant.domain.ContractSignature;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kws.merchant.domain.po.ContractSignaturePo;
import com.kws.merchant.mapper.ContractSignatureMapper;
import com.kws.merchant.service.ContractSignatureService;
import com.kws.system.api.RemoteUserService;
import com.kws.system.api.domain.SysUser;
import com.kws.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;

/**
 * 合同管理-签名管理(ContractSignature)表服务实现类
 *
 * @author yxy
 * @since 2024-10-29 15:37:32
 */
@Service("contractSignatureService")
public class ContractSignatureServiceImpl extends ServiceImpl<ContractSignatureMapper, ContractSignature> implements ContractSignatureService {

    @Resource
    private ContractSignatureMapper contractSignatureMapper;

    /**
     * 分页查询列表
     */
    @Override
    public Page<ContractSignature> pageList(ContractSignaturePo contractSignaturePo) {
        Integer pageSize = contractSignaturePo.getPageSize();
        Integer totalPage = contractSignaturePo.getTotalPage();
        String userName = contractSignaturePo.getUserName();
        String type = contractSignaturePo.getType();
        SysUser sysUser = AuthUtil.getLoginUser().getSysUser();
        //查询自己的签名和盖章
        String sql=" u.user_id="+sysUser.getUserId();
        if (StringUtils.isNotEmpty(userName)){
            sql+=" and u.nick_name like '%"+userName+"%' ";
        }
        if (StringUtils.isNotEmpty(type)){
            sql+=" and s.type="+type;
        }
        int total = contractSignatureMapper.countToTal(sql);
        int sizeNum = (pageSize - 1) * totalPage;//计算分页
        //查询签名数据
        List<ContractSignature> records=contractSignatureMapper.getRecords(sql,sizeNum,totalPage);
        Page<ContractSignature> page = new Page<>();
        page.setRecords(records);
        page.setTotal(total);
        page.setCurrent(pageSize);
        page.setPages((total+totalPage-1)/totalPage);
        page.setSize(totalPage);
        return page;
    }


}
